/*
 * @Author: 张家亮 1690608011@qq.com
 * @Date: 2022-08-17 17:30:22
 * @LastEditors: 张家亮 1690608011@qq.com
 * @LastEditTime: 2022-08-28 21:57:31
 * @FilePath: \vue-store-server\app\models\dao\addrinfoDao.js
 * @Description: 我的收藏模块数据持久层
 * 
 * Copyright (c) 2022 by 张家亮 1690608011@qq.com, All Rights Reserved. 
 */
const db = require('./db.js');

module.exports = {
  // 连接数据库,把地址信息插入数据库
  AddAddrinfo: async (user_id, addr_id) => {
    const sql = 'insert into addrinfo values(null,?,?)';
    return await db.query(sql, [user_id, addr_id]);
  },
  AddAddress: async (provence, city, country, street) => {
    const sql = 'insert into address values(null,?,?,?,?)';
    return await db.query(sql, [provence, city, country, street]);
  },
  UpdateAddress: async (addr_id, provence, city, country, street) => {
    const sql = 'update address set provence=?,city=?,country=?,street=? where addr_id=?';
    return await db.query(sql, [provence, city, country, street, addr_id]);
  },
  // 连接数据库,获取用户的所有地址信息
  GetAddrinfo: async (user_id) => {
    const sql = 'select * from addrinfo where user_id=?';
    return await db.query(sql, user_id);
  },
  // 连接数据库,获取用户的某个地址信息
  FindAddrinfo: async (user_id, addr_id) => {
    const sql = 'select * from addrinfo where user_id=? and addr_id=?';
    return await db.query(sql, [user_id, addr_id]);
  },
  // 连接数据库,删除用户的某个收藏商品信息
  DeleteAddrinfo: async (user_id, addr_id) => {
    const sql = 'delete from addrinfo where user_id=? and addr_id=?';
    return await db.query(sql, [user_id, addr_id]);
  },

  GetAddressById: async (id) => {
    const sql = 'select * from address where addr_id = ?';
    return await db.query(sql, id);
  }
}